// goTop组件
;
! function($) {
    $.fn.totop = function(options) {
        // 默认参数
        var defualts = {
            showtell: true, //显示客服
            showewm: true, //显示二维码
            showwrite: true, //显示反馈
            showtotop: true, //显示返回顶部
        }
        // 扩展对象
        var opts = $.extend({}, defualts, options)
        // 保存对象
        var me = $(this);
        // 初始化对象
        var obj = {

            // 拼接top结构
            fn_structure: function() {
                var tell = '<div class="toolbar-section toolbar-section-tell"><i class="icon icon-tell"></i><div class="toolbar-section-inner">在线客服</div></div>'
                var ewm = '<div class="toolbar-section toolbar-section-ewm"><i class="icon icon-ewm"></i><div class="toolbar-section-ewm-inner"><div class="ewm-top"><img src="http://static-online.zhaogang.com/project/ued/mall/local/Resources/index/newimages/zs-ewm.jpg" alt=""><span>下载找钢指数</span></div><div class="ewm-bottom"><img src="http://static-online.zhaogang.com/project/ued/mall/local/Resources/index/newimages/sd-ewm.jpg" alt=""><span>关注找钢视点</span></div></div></div>'
                var write = ' <div class="toolbar-section toolbar-section-write"><i class="icon icon-write"></i><div class="toolbar-section-inner">反馈</div></div>'
                var totop = '<div class="toolbar-section toolbar-section-totop"><i class="icon icon-totop"></i><div class="toolbar-section-inner">顶部</div></div>'
                var wrap = '<div class="sidetoolbar"><div class="toolbar">' + tell + ewm + write + totop + '</div></div>'
                $('body').append(wrap)

            },
            // 滑动效果
            fn_mouse: function() {
                $(document).on({
                    mouseenter: function() {
                        $(this).addClass('active')
                        $(this).find('.toolbar-section-inner').stop().animate({
                            left: '-59px'
                        })
                    },
                    mouseleave: function() {
                        $(this).removeClass('active')
                        $(this).find('.toolbar-section-inner').stop().animate({
                            left: '0'
                        })
                    }
                }, '.toolbar-section')
                $(document).on({
                    mouseenter: function() {
                        $(this).addClass('active')
                        $(this).find('.toolbar-section-ewm-inner').show().stop().animate({ 'opacity': 1 }, 300)
                    },
                    mouseleave: function() {
                        $(this).removeClass('active')
                        $(this).find('.toolbar-section-ewm-inner').stop().animate({ 'opacity': 0 }, 300, function() {

                            $(this).hide()
                        })
                    }
                }, '.toolbar-section-ewm')
            },
            // 滚动到顶部
            fn_totop: function() {
                $(document).on('click', '.toolbar-section-totop', function() {
                    $('body,html').animate({ scrollTop: 0 }, 500);
                })
                var _height = $(window).height();
                $(window).scroll(function() {
                    if ($(window).scrollTop() >= _height) {
                        $('.toolbar-section-totop').show().stop().animate({ 'opacity': 1 }, 300, function() {
                            $(this).find('.toolbar-section-inner').show()
                        })

                    } else {

                        $('.toolbar-section-totop').hide().find('.toolbar-section-inner').hide()
                        $('.toolbar-section-totop').stop().animate({ 'opacity': 0 }, 300)

                    }

                })
            },
            // 侧边栏显示状态
            fn_state: function() {
                if (!opts.showtell) {
                    $('.toolbar-section-tell').hide();
                }
                if (!opts.showewm) {
                    $('.toolbar-section-ewm').hide();
                }
                if (!opts.showtwrite) {
                    $('.toolbar-section-twrite').hide();
                }
                if (!opts.showtell) {
                    $('.toolbar-section-tell').hide();
                }
            },
            // qq客服
            fn_qq: function() {
                $(document).on('click', '.toolbar-section-tell', function() {
                    window.open('http://crm2.qq.com/page/portalpage/wpa.php?uin=800016576&cref&ref=&f=1&ty=1&ap=&as=&v=')
                })
            },
            // 反馈
            fn_write: function() {
                $(document).on('click', '.toolbar-section-write', function() {
                    $('.hm-t-feedback-trigger').trigger('click')
                })
            },

            init: function() {
                this.fn_structure();
                this.fn_mouse();
                this.fn_totop();
                this.fn_state();
                this.fn_qq();
                this.fn_write();

            }
        }
        obj.init()
    }
}(jQuery)

function goTop() {
    $(document).totop({

    })
}